home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTMLDTD.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  8.5 KB  |  304 lines

  1. /*        Our Static DTD for HTML
  2. **        -----------------------
  3. */
  4.  
  5. /* Implements:
  6. */
  7.  
  8. #include "HTUtils.h"
  9. #include "HTMLDTD.h"
  10. #include "LYLeaks.h"
  11.  
  12. /*     Entity Names
  13. **    ------------
  14. **
  15. **    This table must be matched exactly with ALL the translation tables
  16. */
  17. static CONST char* entities[] = {
  18.   "AElig",    /* capital AE diphthong (ligature) */ 
  19.   "Aacute",    /* capital A, acute accent */ 
  20.   "Acirc",    /* capital A, circumflex accent */ 
  21.   "Agrave",    /* capital A, grave accent */ 
  22.   "Aring",    /* capital A, ring */ 
  23.   "Atilde",    /* capital A, tilde */ 
  24.   "Auml",    /* capital A, dieresis or umlaut mark */ 
  25.   "Ccedil",    /* capital C, cedilla */ 
  26.   "ETH",    /* capital Eth, Icelandic */ 
  27.   "Eacute",    /* capital E, acute accent */ 
  28.   "Ecirc",    /* capital E, circumflex accent */ 
  29.   "Egrave",    /* capital E, grave accent */ 
  30.   "Euml",    /* capital E, dieresis or umlaut mark */ 
  31.   "Iacute",    /* capital I, acute accent */ 
  32.   "Icirc",    /* capital I, circumflex accent */ 
  33.   "Igrave",    /* capital I, grave accent */ 
  34.   "Iuml",    /* capital I, dieresis or umlaut mark */ 
  35.   "Ntilde",    /* capital N, tilde */ 
  36.   "Oacute",    /* capital O, acute accent */ 
  37.   "Ocirc",    /* capital O, circumflex accent */ 
  38.   "Ograve",    /* capital O, grave accent */ 
  39.   "Oslash",    /* capital O, slash */ 
  40.   "Otilde",    /* capital O, tilde */ 
  41.   "Ouml",    /* capital O, dieresis or umlaut mark */ 
  42.   "THORN",    /* capital THORN, Icelandic */ 
  43.   "Uacute",    /* capital U, acute accent */ 
  44.   "Ucirc",    /* capital U, circumflex accent */ 
  45.   "Ugrave",    /* capital U, grave accent */ 
  46.   "Uuml",    /* capital U, dieresis or umlaut mark */ 
  47.   "Yacute",    /* capital Y, acute accent */ 
  48.   "aacute",    /* small a, acute accent */ 
  49.   "acirc",    /* small a, circumflex accent */ 
  50.   "aelig",    /* small ae diphthong (ligature) */ 
  51.   "agrave",    /* small a, grave accent */ 
  52.   "amp",    /* ampersand */ 
  53.   "aring",    /* small a, ring */ 
  54.   "atilde",    /* small a, tilde */ 
  55.   "auml",    /* small a, dieresis or umlaut mark */ 
  56.   "ccedil",    /* small c, cedilla */ 
  57.   "eacute",    /* small e, acute accent */ 
  58.   "ecirc",    /* small e, circumflex accent */ 
  59.   "egrave",    /* small e, grave accent */ 
  60.   "emsp",    /* em space - not collapsed */
  61.   "ensp",    /* en space - not collapsed */
  62.   "eth",    /* small eth, Icelandic */ 
  63.   "euml",    /* small e, dieresis or umlaut mark */ 
  64.   "gt",        /* greater than */ 
  65.   "iacute",    /* small i, acute accent */ 
  66.   "icirc",    /* small i, circumflex accent */ 
  67.   "igrave",    /* small i, grave accent */ 
  68.   "iuml",    /* small i, dieresis or umlaut mark */ 
  69.   "lt",        /* less than */ 
  70.   "nbsp",       /* non breaking space */
  71.   "ntilde",    /* small n, tilde */ 
  72.   "oacute",    /* small o, acute accent */ 
  73.   "ocirc",    /* small o, circumflex accent */ 
  74.   "ograve",    /* small o, grave accent */ 
  75.   "oslash",    /* small o, slash */ 
  76.   "otilde",    /* small o, tilde */ 
  77.   "ouml",    /* small o, dieresis or umlaut mark */ 
  78.   "quot",    /* quot '"' */
  79.   "szlig",    /* small sharp s, German (sz ligature) */ 
  80.   "thorn",    /* small thorn, Icelandic */ 
  81.   "uacute",    /* small u, acute accent */ 
  82.   "ucirc",    /* small u, circumflex accent */ 
  83.   "ugrave",    /* small u, grave accent */ 
  84.   "uuml",    /* small u, dieresis or umlaut mark */ 
  85.   "yacute",    /* small y, acute accent */ 
  86.   "yuml",    /* small y, dieresis or umlaut mark */ 
  87. };
  88.  
  89. #define HTML_ENTITIES 69
  90.  
  91.  
  92. /*        Attribute Lists
  93. **        ---------------
  94. **
  95. **    Lists must be in alphatbetical order by attribute name
  96. **    The tag elements contain the number of attributes
  97. */
  98. static attr no_attr[] = 
  99.     {{ 0 }};
  100.  
  101. static attr a_attr[] = {            /* Anchor attributes */
  102.     { "HREF"},
  103.     { "NAME" },                /* Should be ID */
  104.     { "TITLE" },
  105.     { "TYPE" },
  106.     { "URN" },
  107.     { 0 }    /* Terminate list */
  108. };    
  109.  
  110. static attr base_attr[] = {            /* BASE attributes */
  111.     { "HREF"},
  112.     { 0 }    /* Terminate list */
  113. };    
  114.  
  115. static attr img_attr[] = {            /* IMG attributes */
  116.     { "ALT"},
  117.     { "ISMAP"},
  118.     { "SRC"},
  119.     { 0 }    /* Terminate list */
  120. };    
  121.  
  122. static attr isindex_attr[] = {            /* ISINDEX attributes */
  123.     { "ACTION"},    /* Not in spec.  Lynx treats it as HREF. - FM */
  124.     { "HREF"},    /* HTML 3.0 attritute for search action. - FM */ 
  125.     { "PROMPT"},    /* HTML 3.0 attribute for prompt string. - FM */
  126.     { 0 }    /* Terminate list */
  127. };    
  128.  
  129. static attr link_attr[] = {
  130.     { "HREF"},
  131.     { "REL"},
  132.     { "REV"},
  133.     { 0 }    /* Terminate list */
  134. };
  135.  
  136. static attr form_attr[] = {
  137.     { "ACTION"},
  138.     { "ENCTYPE"},
  139.     { "METHOD"},
  140.     { 0 }    /* Terminate list */
  141. };
  142.  
  143. static attr select_attr[] = {
  144.     { "MULTIPLE" },
  145.     { "NAME" },
  146.     { "SIZE" },
  147.     { 0 }    /* Terminate list */
  148. };
  149.  
  150. static attr option_attr[] = {
  151.     { "SELECTED"},
  152.     { "VALUE"},
  153.     { 0 }    /* Terminate list */
  154. };
  155.  
  156. static attr textarea_attr[] = {
  157.     { "COLS"},
  158.     { "NAME"},
  159.     { "ROWS"},
  160.     { 0 }    /* Terminate list */
  161. };
  162.  
  163. static attr input_attr[] = {
  164.     { "CHECKED"},
  165.     { "MAXLENGTH"},
  166.     { "NAME"},
  167.     { "SIZE"},
  168.     { "TYPE"},
  169.     { "VALUE"},
  170.     { 0 } /* Terminate list */
  171. };
  172.  
  173. static attr list_attr[] = {
  174.     { "COMPACT"},
  175.     { 0 }    /* Terminate list */
  176. };
  177.  
  178. static attr glossary_attr[] = {
  179.     { "COMPACT" },
  180.     { 0 }    /* Terminate list */
  181. };
  182.  
  183. static attr nextid_attr[] = {
  184.     { "N" }
  185. };
  186.  
  187. static attr mh_attr[]    =    {
  188.     { "HIDDEN" },
  189.     { 0 }    /* Terminate list */
  190. };
  191.  
  192. /*    Elements
  193. **    --------
  194. **
  195. **    Must match definitions in HTMLDTD.html!
  196. **    Must be in alphabetical order.
  197. **
  198. **    Name,     Attributes,         content
  199. */
  200. static HTTag tags[HTML_ELEMENTS] = {
  201.     { "A"    , a_attr,    HTML_A_ATTRIBUTES,    SGML_MIXED },
  202.     { "ADDRESS"    , no_attr,    0,        SGML_MIXED },
  203.     { "B"    , no_attr,    0,        SGML_MIXED },
  204.     { "BASE"    , base_attr,    HTML_BASE_ATTRIBUTES,    SGML_EMPTY },
  205.     { "BLOCKQUOTE", no_attr,    0,        SGML_MIXED },
  206.     { "BODY"    , no_attr,    0,        SGML_MIXED },
  207.     { "BR"    , no_attr,    0,        SGML_EMPTY },
  208.     { "CITE"    , no_attr,    0,        SGML_MIXED },
  209.     { "CODE"    , no_attr,    0,        SGML_MIXED },
  210.     { "COMMENT",  no_attr,    0,        SGML_MIXED },
  211.     { "DD"    , no_attr,    0,        SGML_EMPTY },
  212.     { "DFN"    , no_attr,    0,        SGML_MIXED },
  213.     { "DIR"    , list_attr,    1,        SGML_MIXED },
  214.     { "DL"    , glossary_attr,1,        SGML_MIXED },
  215.     { "DLC"    , glossary_attr,1,        SGML_MIXED },
  216.     { "DT"    , no_attr,    0,        SGML_EMPTY },
  217.     { "EM"    , no_attr,    0,        SGML_MIXED },
  218.     { "FORM"    , form_attr,    HTML_FORM_ATTRIBUTES,    SGML_MIXED },
  219.     { "H1"    , no_attr,    0,        SGML_MIXED },
  220.     { "H2"    , no_attr,    0,        SGML_MIXED },
  221.     { "H3"    , no_attr,    0,        SGML_MIXED },
  222.     { "H4"    , no_attr,    0,        SGML_MIXED },
  223.     { "H5"    , no_attr,    0,        SGML_MIXED },
  224.     { "H6"    , no_attr,    0,        SGML_MIXED },
  225.     { "H7"    , no_attr,    0,        SGML_MIXED },
  226.     { "HEAD"    , no_attr,    0,        SGML_MIXED },
  227.     { "HR"    , no_attr,    0,        SGML_EMPTY },
  228.     { "HTML"    , no_attr,    0,        SGML_MIXED },
  229.     { "I"    , no_attr,    0,        SGML_MIXED },
  230.     { "IMG"     , img_attr,    HTML_IMG_ATTRIBUTES,    SGML_EMPTY },
  231.     { "INPUT"   , input_attr,    HTML_INPUT_ATTRIBUTES,    SGML_EMPTY },
  232.     { "ISINDEX" , isindex_attr,    HTML_ISINDEX_ATTRIBUTES,SGML_EMPTY },
  233.     { "KBD"    , no_attr,    0,        SGML_MIXED },
  234.     { "LI"    , list_attr,    1,        SGML_EMPTY },
  235.     { "LINK"    , link_attr,    HTML_LINK_ATTRIBUTES,    SGML_EMPTY },
  236.     { "LISTING"    , no_attr,    0,        SGML_LITTERAL },
  237.     { "MENU"    , list_attr,    1,        SGML_MIXED },
  238.     { "MH"    , mh_attr,    HTML_MH_ATTRIBUTES,    SGML_LITTERAL },
  239.     { "NEXTID"  , nextid_attr,    1,        SGML_EMPTY },
  240.     { "OL"    , list_attr,    1,        SGML_MIXED },
  241.     { "OPTION"    , option_attr,    HTML_OPTION_ATTRIBUTES,    SGML_EMPTY },
  242.     { "P"    , no_attr,    0,        SGML_EMPTY },
  243.     { "PLAINTEXT", no_attr,    0,        SGML_LITTERAL },
  244.     { "PRE"    , no_attr,    0,        SGML_MIXED },
  245.     { "SAMP"    , no_attr,    0,        SGML_MIXED },
  246.     { "SELECT"    , select_attr,    HTML_SELECT_ATTRIBUTES,    SGML_MIXED },
  247.     { "STRONG"    , no_attr,    0,        SGML_MIXED },
  248.     { "TEXTAREA", textarea_attr,HTML_TEXTAREA_ATTRIBUTES, SGML_MIXED },
  249.     { "TITLE",       no_attr,    0,        SGML_RCDATA },
  250.     { "TT"    , no_attr,    0,        SGML_MIXED },
  251.     { "U"    , no_attr,    0,        SGML_MIXED },
  252.     { "UL"    , list_attr,    1,        SGML_MIXED },
  253.     { "VAR"    , no_attr,    0,        SGML_MIXED },
  254.     { "XMP"    , no_attr,    0,        SGML_LITTERAL },
  255. };
  256.  
  257.  
  258. PUBLIC CONST SGML_dtd HTML_dtd = {
  259.     tags,
  260.     HTML_ELEMENTS,
  261.     entities,
  262.     sizeof(entities)/sizeof(char**)
  263. };
  264.  
  265. /*    Utility Routine: useful for people building HTML objects */
  266.  
  267. /*    Start anchor element
  268. **    --------------------
  269. **
  270. **    It is kinda convenient to have a particulr routine for
  271. **    starting an anchor element, as everything else for HTML is
  272. **    simple anyway.
  273. */
  274. struct _HTStructured {
  275.     HTStructuredClass * isa;
  276.     /* ... */
  277. };
  278.  
  279. PUBLIC void HTStartAnchor ARGS3(HTStructured *, obj,
  280.         CONST char *,  name,
  281.         CONST char *,  href)
  282. {
  283.     BOOL        present[HTML_A_ATTRIBUTES];
  284.     CONST char *     value[HTML_A_ATTRIBUTES];
  285.     
  286.     {
  287.         int i;
  288.         for(i=0; i<HTML_A_ATTRIBUTES; i++)
  289.         present[i] = NO;
  290.     }
  291.     if (name) {
  292.         present[HTML_A_NAME] = YES;
  293.     value[HTML_A_NAME] = (CONST char *)name;
  294.     }
  295.     if (href) {
  296.         present[HTML_A_HREF] = YES;
  297.         value[HTML_A_HREF] = (CONST char *)href;
  298.     }
  299.     
  300.     (*obj->isa->start_element)(obj, HTML_A , present, value);
  301.  
  302. }
  303.  
  304.